<?php
namespace app\agent\controller\system;
use think\Db;
class BusWithdrawal extends \app\agent\controller\Common
{
    public function index(){
        return view();
    }

    public function list(){
        $limit = request()->param('limit') ?? 15;
        $page = request()->param('page');
        $page = $page ? ($page - 1) * $limit : 0;
        $search = request()->param();
        $query = (new \app\common\model\BusWithdrawal())->where(['agent_id' => $this->userInfo['id']]);
        isset($search['title']) && $search['title'] != "" ? $query->where("title like '%{$search['title']}%'") : '';
        isset($search['state']) && $search['state'] != "" ? $query->where("state like '%{$search['state']}%'") : '';
        $query->order("id desc");
        $list = $query->append(['addtime_text','state_text','bus_title'])->limit($page, $limit)->select();
      
        $count = $query->count();
   
        return self::successResult('',$list,$count);
    }


    
    public function info()
    {
        if (request()->isPost()) {
            $data = request()->param('info');
            $id = request()->param('id');

            $table = new \app\common\model\BusWithdrawal();
            $row = $table->allowField(true)->save($data, ['id' => $id]);
            if ($row) {
                return self::successResult();
            } else {
                return self::errorResult();
            }
        } else {
            $id = intval(request()->param('id'));
            $info = (new \app\common\model\BusWithdrawal())
                    ->where(['id' => $id])
                    ->append(['addtime_text','state_text','bus_title','user_title'])
                    ->find();
            $this->assign('info',$info);
            return view();
        }
    }



  

 
}
